local hl_ex__qizhi = fk.CreateSkill {
  name = "hl_ex__qizhi",
}

Fk:loadTranslationTable{
  ["hl_ex__qizhi"] = "奇制",
  [":hl_ex__qizhi"] = "当你于回合内使用非装备牌指定目标后，你可以弃置一名不为目标的角色的一张牌，然后若此牌与你使用的牌类别相同，则你摸一张牌，否则其摸一张牌。",
  ["@hl_ex__qizhi-turn"] = "奇制",
  ["#hl_ex__qizhi-choose"] = "奇制：你可以弃置一名角色一张牌，根据类别令你或其摸一张牌",

  ["$hl_ex__qizhi1"] = "兵动而无功，威名折于外。",
  ["$hl_ex__qizhi2"] = "虽积兵江内，无必渡之势。",
}

hl_ex__qizhi:addEffect(fk.TargetSpecified, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hl_ex__qizhi.name) and player.room.current == player and
      data.firstTarget and data.card.type ~= Card.TypeEquip and
      table.find(player.room.alive_players, function (p)
        return not p:isNude()
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function(p)
      return not p:isNude() and not table.contains(data.use.tos, p)
    end)
    if table.contains(targets, player) and
      not table.find(player:getCardIds("he"), function (id)
        return not player:prohibitDiscard(id)
      end) then
      table.removeOne(targets, player)
    end
    if #targets == 0 then
      room:askToCards(player, {
        min_num = 1,
        max_num = 1,
        include_equip = false,
        skill_name = hl_ex__qizhi.name,
        pattern = "false",
        prompt = "#hl_ex__qizhi-choose",
        cancelable = true,
      })
    else
      local to = room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = targets,
        skill_name = hl_ex__qizhi.name,
        prompt = "#hl_ex__qizhi-choose",
        cancelable = true,
      })
      if #to > 0 then
        event:setCostData(self, {tos = to})
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@hl_ex__qizhi-turn", 1)
    local to = event:getCostData(self).tos[1]
    if to == player then
      room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = hl_ex__qizhi.name,
        cancelable = false,
      })
      if not to.dead then
        to:drawCards(1, hl_ex__qizhi.name)
      end
    else
      local id = room:askToChooseCard(player, {
        target = to,
        flag = "he",
        skill_name = hl_ex__qizhi.name,
      })
      room:throwCard(id, hl_ex__qizhi.name, to, player)
      if not to.dead then
        if Fk:getCardById(id).type == data.card.type then
          player:drawCards(1, hl_ex__qizhi.name)
        else to:drawCards(1, hl_ex__qizhi.name)
        end
      end
    end
  end,
})

return hl_ex__qizhi